﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hr.DAL;
using Hr.IDAL;
using Hr.Model;


namespace Hr.BLL
{
    public class FinanceService
    {
        //引入wageDal 层并实例化
        //bll层调用dal层方法，控制器调用bll层方法
        protected FinanceDAL Finance = new FinanceDAL();

        protected FinanceDAL Rdl = new FinanceDAL();
        /// <summary>
        /// 获取账号信息
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, object> GetMailAccountL(int page, int limit)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"FinanceAccount",Finance.GetMailAccount().Skip(limit*(page-1)).Take(limit) },
                {"Count",Finance.GetMailAccount().Count() }
            };
            return dt;
        }
        /// <summary>
        /// 获取财务报表
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, object> GetMailAccount(int page, int limit)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"FinanceAccount",Finance.GetMailList().Skip(limit*(page-1)).Take(limit) },
                {"Count",Finance.GetMailList().Count() }
            };
            return dt;
        }
        /// <summary>
        /// 根据账号ID，获取账号信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Finance_Account GetFinanceInfo(int id)
        {
            return Finance.GetFinanceInfo(id);//调用Dal层的GetRoleName方法
        }
        /// <summary>
        /// 根据财务ID，获取财务信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Finance_List GetFinancelinsInfo(int id)
        {
            return Finance.GetFinancelisnInfo(id);//调用Dal层的GetRoleName方法
        }
        /// <summary>
        /// 获取Finance_Account需要添加的数据，修改数据
        /// </summary>
        public bool UpdateFinanceList(Finance_Account r, string type,int pk_User)
        {
            Finance.UpdateFinance(r, type,pk_User);
            return Finance.SaveChanges();
        }
        /// <summary>
        /// 获取Finance_List需要添加的数据，修改数据
        /// </summary>
        public bool UpdateFinance(Finance_List r, string type,int pk_User)
        {
            Finance.UpdateFinancelin(r, type,pk_User);
            return Finance.SaveChanges();
        }
        /// <summary>
        /// 获取账号类型
        /// </summary>
        /// <returns></returns>
        public IEnumerable<object> GetTypeList()
        {
            return Finance.GetTypeList("Finance_Account").Select(n => new
            {
                n.ID,
                n.TypeName_CHS
            });
        }
        /// <summary>
        /// 获取账号状态
        /// </summary>
        /// <returns></returns>
        public IEnumerable<object> GetStatusList()
        {
            return Finance.GetStatusList("Finance_Account").Select(n => new
            {
                n.ID,
                n.StatusName_CHS
            });
        }
        /// <summary>
        /// 获取财务类型
        /// </summary>
        /// <returns></returns>
        public IEnumerable<object> GetTypeList2()
        {
            return Finance.GetTypeList("Finance_List").Select(n => new
            {
                n.ID,
                n.TypeName_CHS
            });
        }
        /// <summary>
        /// 获取财务状态
        /// </summary>
        /// <returns></returns>
        public IEnumerable<object> GetStatusList2()
        {
            return Finance.GetStatusList("Finance_List").Select(n => new
            {
                n.ID,
                n.StatusName_CHS
            });
        }
        /// <summary>
        /// 获取财务部门
        /// </summary>
        /// <returns></returns>
        public IEnumerable<User_Department> GetTypeList3()
        {
            return Rdl.GetTypeList3();
        }
        /// <summary>
        /// 获取财务
        /// </summary>
        /// <returns></returns>
        public IEnumerable<object> GetStatusList3()
        {
            return Rdl.GetStatusList3();
        }
        /// <summary>
        /// 根据FullName查询Finance_Account表数据
        /// </summary>
        /// <returns></returns>
        //public IEnumerable<Finance_Account> FNameSelectFinanceList(string AccountName)
        //{
        //    return Finance.FNameSelectFinanceList(AccountName);
        //}
        public Dictionary<string, object> FNameSelectFinanceList(int page, int limit, string AccountName)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"FinanceAccount",Finance.FNameSelectFinanceList(AccountName).Skip(limit*(page-1)).Take(limit) },
                {"Count",Finance.FNameSelectFinanceList(AccountName).Count() }
            };
            return dt;
        }
        /// <summary>
        /// 根据FullName查询Finance_List表数据
        /// </summary>
        /// <returns></returns>Title
        //public IEnumerable<Finance_List> FNameSelectFinance(string Title)
        //{
        //    return Finance.FNameSelectFinance(Title);
        //}
        public Dictionary<string, object> FNameSelectFinance(int page, int limit, string Title)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"FinanceAccount",Finance.FNameSelectFinance(Title).Skip(limit*(page-1)).Take(limit) },
                {"Count",Finance.FNameSelectFinance(Title).Count() }
            };
            return dt;
        }
        /// <summary>
        /// 删除账号信息
        /// </summary>
        /// <param name="pk_Name"></param>
        /// <returns></returns>
        public bool DelAccountdata(int pk_Account)
        {
            Finance.DelAccountdata(Finance.GetFinanceInfo(pk_Account));
            return Finance.SaveChanges();
        }
        /// <summary>
        /// 删除财务信息
        /// </summary>
        /// <param name="pk_Name"></param>
        /// <returns></returns>
        public bool DelFinancedata(int pk_Finance)
        {
            Finance.DelFinancedata(Finance.GetFinance(pk_Finance));
            return Finance.SaveChanges();
        }

        #region 财务报表
        /// <summary>
        /// 收入
        /// </summary>
        /// <returns></returns>
        public IEnumerable<object> FinanceIncome()
        {
            return Finance.FinanceIncome();
        }

        /// <summary>
        /// 支出
        /// </summary>
        /// <returns></returns>
        public IEnumerable<object> FinancePay()
        {
            return Finance.FinancePay();
        }
        /// <summary>
        /// 待定
        /// </summary>
        /// <returns></returns>
        public IEnumerable<object> Financeindeterminate()
        {
            return Finance.Financeindeterminate();
        }
        /// <summary>
        /// 获取盈利的数据
        /// </summary>
        /// <returns></returns>
        public List<Dictionary<string, string>> GetFinceInfo()
        {
            return Finance.GetFinceInfo();
        }
        /// <summary>
        /// 详细报表
        /// </summary>
        /// <returns></returns>
        public List<object> ReportList()
        {
            return Finance.ReportList();
        }
        #endregion
    }
    }
